package adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.example.administrator.boltshow.R;

import org.xutils.x;

import java.util.List;

import model.MineModel;

/**
 * Created by Administrator on 2016/8/26.
 */
public class MineFragmentAdapter extends RecyclerView.Adapter<MineFragmentAdapter.ClassifyViewHolder> {

    private List<MineModel.LinksBean> mData;
    private Context mContext;
    public MineFragmentAdapter(List<MineModel.LinksBean> mData, Context mContext){
        this.mContext =mContext;
        this.mData = mData;
    }

    @Override
    public ClassifyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(mContext).inflate(R.layout.mine_fragment_item,null);
        ClassifyViewHolder holder = new ClassifyViewHolder(view);
        return holder;
    }

    @Override
    public void onBindViewHolder(ClassifyViewHolder holder, final int position) {
        MineModel.LinksBean linksBean = mData.get(position);
        holder.mImageView.setScaleType(ImageView.ScaleType.FIT_XY);
        x.image().bind(holder.mImageView,linksBean.getIcon());
        holder.mTextView.setText(linksBean.getName());
    }

    @Override
    public int getItemCount() {
        return mData ==null?0:mData.size();
    }

    static class ClassifyViewHolder extends RecyclerView.ViewHolder{

        private TextView mTextView;
        private ImageView mImageView;
        public ClassifyViewHolder(View itemView) {
            super(itemView);

            mTextView = (TextView) itemView.findViewById(R.id.tv_classify_fragment_item);
            mImageView = (ImageView) itemView.findViewById(R.id.iv_classify_fragment_item);

        }
    }
}
